<?php
/**
 * Created by PhpStorm.
 * User: wx:wenyi2048
 * Date: 2022/6/22 0022
 * Time: 09:19
 */

namespace app\common\service;


class SpoilsService extends Service
{
    protected $tableName = 'sms_mk_spoils';

    protected function dbQuery(){
        $this->db->alias('sp')
            ->join('sms_mk_orders o','o.id = sp.order_id','right')
            //->join('sms_mk_stores s','s.id = o.store_id')
            //->where('o.state','<>','require')
            ->order('o.id','desc')
            ->field("o.*,sp.id as sp_id,sp.body_type,sp.spoils_no,sp.spoils_percent,sp.spoils_fee,sp.state as sp_state");
    }
    /**
     * @param $view
     * @param $params
     * @param int $isdelete  返回全部订单分页
     */
    public function searchPage(&$view,$params,$isdelete = 0){
        $this->dbQuery();
        if(@$params['number']) $this->db->where('o.number','like','%'.$params['number'].'%');
        $storeId = $this->checkStoreSelect(@$params['store_id']);
        if($storeId) $this->db->where('o.store_id','=',$storeId);
        $this->pageList($view,$params);
    }

    public function getSpoils($orderId){
        $this->dbQuery();
        $this->db->where('o.order_id','=',$orderId);
        return $this->db->find();
    }

}